/*
 * NyuStrPool.hpp
 *
 *  Created on: 2010/05/22
 *      Author: mitsu
 */

#ifndef NYUSTRPOOL_HPP_
#define NYUSTRPOOL_HPP_

#include <cstddef>

class NyuString;
class NyuStaticString;
class NyuStrPool {
public:
	NyuString* get(char* str, int);

	static void initialize();
	static void finalize();

	static NyuStrPool* getInstance() {
		return instance_;
	}

	static NyuString* get(char* str) {
		return instance_->get(str, 0);
	}

	static void addStatic(NyuStaticString* str);

private:
	NyuStrPool();
	~NyuStrPool();

	struct Entry {
	    Entry(NyuString* v, Entry* n = 0) :
	        value(v), next(n) {}
	    ~Entry();

	    NyuString* value;
	    Entry* next;
	};

	Entry** ents_;
	size_t nents_;

	void rehash();
    void add(NyuString* str);

private:
	static NyuStrPool* instance_;
};

#endif /* NYUSTRPOOL_HPP_ */
